const onValidator = (rule, value, callback) => {
  if (!rule.required) {
    callback()
  } else if (value || value === 0 || value === false) {
    callback()
  } else {
    callback(new Error(rule.info))
  }
}
export default onValidator

const login = {
  username: [{ required: true, trigger: 'blur', info: '请输入账号！', validator: onValidator }],
  password: [{ required: true, trigger: 'blur', info: '请输入密码！', validator: onValidator }]
}

const personnelManagement = {
  name: [
    { required: true, trigger: 'blur', info: '请输入姓名', validator: onValidator }
  ],
  school_name: [
    { required: true, trigger: 'blur', info: '请输入单位名称', validator: onValidator }
  ],
  email: [
    { type: 'email', trigger: ['blur', 'change'], message: '请输入正确的邮箱地址' }
  ],
  mobile: [
    { required: true, trigger: 'blur', info: '请输入手机号', validator: onValidator },
    { min: 11, max: 11, trigger: ['blur', 'change'], message: '请输入11位数字值手机号' }
  ],
  password: [
    { required: true, trigger: 'blur', info: '请输入登录密码', validator: onValidator },
    { min: 6, max: 16, trigger: ['blur', 'change'], message: '密码长度在 6 到 16 个字符之间' }
  ]
}

const name = {
  name: [{ required: true, trigger: 'blur', info: '请输入名称！', validator: onValidator }]
}

const department = {
  name: [{ required: true, trigger: 'blur', info: '部门名称不能为空', validator: onValidator }],
  // abbreviated_name: [{ required: true, trigger: 'blur', info: '简称不能为空', validator: onValidator }],
  type: [{ required: true, trigger: 'blur', info: '部门类型为必选', validator: onValidator }]
}

const courses = {}
// evaluateSet —— 评课说明
const introduce = {
  commitment: [{ required: true, trigger: ['blur', 'change'], info: '说明内容不能为空', validator: onValidator }],
  acad_year_term: [{ required: true, trigger: ['blur', 'change'], info: '学年学期不能为空', validator: onValidator }]
}

// indicator —— 指标
const indicator = {
  indicator_type: [{ required: true, trigger: ['blur', 'change'], info: '指标类型不能为空', validator: onValidator }],
  evaluation_system_id: [{ required: true, trigger: ['blur', 'change'], info: '请选择体系', validator: onValidator }]
}

// evaluateSet —— 时间设定
const timeset = {
  acad_year_term: [{ required: true, trigger: ['blur', 'change'], info: '学年学期不能为空', validator: onValidator }],
  expertPickerTime: [{ type: 'array', required: true, message: '专家评审时间不能为空' }],
  teacherPickerTime: [{ type: 'array', required: true, message: '教师申报时间不能为空' }],
  principalAuditTime: [{ type: 'array', required: true, message: '学院审核时间不能为空' }]
}
// evaluateSet —— 承诺书
const undertak = {
  commitment: [{ required: true, trigger: ['blur', 'change'], info: '承诺内容不能为空', validator: onValidator }],
  acad_year_term: [{ required: true, trigger: ['blur', 'change'], info: '学年学期不能为空', validator: onValidator }]
}

const validateField = {
  'Login': { ...login },
  'Specialty': { ...name },
  'Nature': { ...name },
  'Department': { ...department },
  'Personnel': { ...personnelManagement },
  'EvaluationCourseExpert': { ...personnelManagement },
  'NewEvaluationCourseExpert': { ...personnelManagement },
  'Expert': { ...personnelManagement },
  'DepartmentExpert': { ...personnelManagement },
  'JobTitle': { ...name },
  'Courses': { ...courses },
  'TeacherCourses': { ...courses },
  'Undertak': { ...undertak },
  'Timeset': { ...timeset },
  'Introduce': { ...introduce },
  '/indicator/index': { ...indicator }
}
export { validateField }

